﻿using OCR.Config;
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;

namespace OCR.SystemThread
{
    class OutputDelayNgSingleThread
    {
        public static bool OutputDelayNgSingleThread_Flowrec = false;
        public static Thread OutputDelayNgSingleFlow_Thread = null;

        public static int iOutputDelayNgSingle_Step = 0;

        public static bool OutputDelayNgSingleThread_Pause = false;

        public static DateTime startDt;

       public static ConcurrentQueue<bool> outputQueue = new ConcurrentQueue<bool>();


        public static int _delayCount = 3;

        public static void OutputDelayNgSingle_Thread()
        {
            iOutputDelayNgSingle_Step = 0;
            OutputDelayNgSingleThread_Pause = false;
            OutputDelayNgSingleThread_Flowrec = true;
            OutputDelayNgSingleFlow_Thread = new Thread(OutputDelayNgSingleThreadFlow);
            OutputDelayNgSingleFlow_Thread.IsBackground = true;
            OutputDelayNgSingleFlow_Thread.Start();
            Console.WriteLine("----OutputDelayNgSingleThread启动");
        }

        private static void OutputDelayNgSingleThreadFlow()
        {
            while (OutputDelayNgSingleThread_Flowrec)
            {
                if (!OutputDelayNgSingleThread_Pause)
                {
                    switch (iOutputDelayNgSingle_Step)
                    {
                        case 0:

                            if (outputQueue.TryDequeue(out bool value))
                            {
                                Console.WriteLine("outputQueue: ----------" + value);
                                if (!value)
                                {
                                    Console.WriteLine("-----输出结果一次----");

                                    IOThread_Run.DO_Trigger_olng(1, 1);
                                    Console.WriteLine("-----发送打开DO一次----");
                                    Thread.Sleep(int.Parse(LocalInfo.NG_Action));
                                    Console.WriteLine("-----吹气一次----");
                                    IOThread_Run.DO_Trigger_olng(1, 0);
                                    Console.WriteLine("-----发送关闭DO一次----");
                                }
                                else if (value)
                                {
                                    break;
                                }
                            }
                            break;
                        case 5:

                            break;
                        case 10:

                            break;

                        case 15:

                            break;
                        case 20:

                            break;
                        case 25:

                            break;
                    }
                }


            }

        }
    }
}
